const app = getApp();
var httpClient = require("../../../utils/HttpClient.js");

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    listData: [],
    listDataAll: [],
    searchValue: "",
  },
  search: function() {
    if (this.data.listDataAll.length == 0) {
      httpClient.superAjax({
        isWebService: true,
        url: 'CustomerService.asmx/getElevatorInfoMin',
        data: {
          CustomerNumber: this.data.userInfo.mp.CustomerNumber,
          PlaceNumber: '',
          UseAddress: '',
          _this: this
        },
        success: function(data) {
          this.data._this.setData({
            listDataAll: data,
            listData: data
          });
          console.log(data);
        }
      })
    } else {
      var sv = this.data.searchValue;
      if (sv != "") {
       var listData =[];
        for (var index in this.data.listDataAll) {
          var t = this.data.listDataAll[index];
          if ( t.PlaceNumber.indexOf(sv) > -1 || t.UseAddress.indexOf(sv) > -1) {
            listData.push(t);
          }
        }
        this.setData({
          listData: listData
        })
      }else{
        this.setData({
          listData: this.data.listDataAll
        })
      }

      


    }











  },


  onLoad() {
    this.setData({
      userInfo: app.globalData.userInfo
    });
    this.search();

  },

  changeInput(e) {
    console.log("e", e)

    let changed = {};
    let prop = e.currentTarget.dataset.prop
    console.log("prop", prop)
    changed[prop] = e.detail.value;
    console.log("changed", changed)
    this.setData(changed)
    this.search();

  },
  itemClick: function(e) {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      evevator: this.data.listData[e.currentTarget.dataset.index]
    })
    wx.navigateBack({
      delta: 1
    })
  }



});